//获取应用实例
var app = getApp();
Page({
    data: {
		codeSetColour: true,
		orderId: ''
	},
	
    onLoad(options) {
		let cacheOrderPay = app.getStorageSync(app.globalData.cacheOrderPay);
		console.log(cacheOrderPay)
		this.setData({
			orderId: options.orderId,
			contactName: cacheOrderPay['address.contactName'],
			cellNum: cacheOrderPay['address.cellNum'],
			fullAddr: cacheOrderPay['address.fullAddr'],
			goodsTypeName: cacheOrderPay.goodsTypeName,
			sendTypeName: cacheOrderPay.sendTypeName,
			timeDiffer: "(" + cacheOrderPay.timeDiffer + ")" + "取消订单",
		})
		
		if (cacheOrderPay.timeDiffer > 0) {
			let second = cacheOrderPay.timeDiffer; //用来记录秒
			let that = this;
			let repeat= setInterval(() => {
				second--;
				let btnText = '('+second +')'+ '取消订单'; //显示时间
				that.setData({
					timeDiffer: btnText
				});
				if (second == 0) {
					btnText = "取消订单";
					clearInterval(repeat);
					that.setData({
						timeDiffer: btnText,
						codeSetColour: false
					});
				} //到过60秒时停止
			}, 1000); //每1000毫秒即1秒执行一次此函数
		}
	},

	//倒计时
	countDown(result) {
		if (this.data.codeSetColour) {
			let opt = {
				url: app.globalData.host+"/wx/sd/co.ajax",				
				data: {
					'orderId': this.data.orderId,
					'payType': 0
				},
				sucFn: (result) => {
					app.errorToast('已成功取消订单');
					setTimeout(()=>{
						wx.navigateBack()  
					},1000)
					
				}
			}
			app.ajax(opt);
		}
	},

	toUrl() {
		app.redirectTo({url:'../orderdetail/orderdetail?orderId=' + this.data.orderId})	
	}
});
